package com.andy.qi.service;

import java.util.Collections;

import com.corundumstudio.socketio.SocketIOClient;

public class SocketClient {
    
    private SocketIOClient client;
    public GameMgr gameMgr;
    public String userId;
    public String address;
    

    public SocketClient(SocketIOClient client) {
        this.client = client;
    }
    
    public void emit(String event, Object data) {
        client.sendEvent(event, data);
    }
    
    public void emit(String event) {
        client.sendEvent(event, (Object)Collections.emptyMap());
    }

    public void disconnect() {
        client.disconnect();
    }
    
    public static SocketClient from(SocketIOClient client) {
        SocketClient c = client.get("client");
        if(c == null) {
            c = new SocketClient(client);
            client.set("client", c);
        }
        return c;
    }

}
